package com.wlyuan.open.remote.consumer;

import com.wlyuan.core.domain.event.DomainEventPublisher;
import com.wlyuan.open.infrastructure.event.OrderChanged;
import com.wlyuan.open.remote.converter.OrderMessageConverter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.var;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

/**
 * @author lijing
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class OrderSignDelayMarkConsumer {
    private final OrderMessageConverter messageConverter = new OrderMessageConverter();

    @RabbitListener(bindings = {
            @QueueBinding(value = @Queue(value = "queue.open.pusher.order.sign.delayMark"),
                    exchange = @Exchange(value = "exchange.topic.order"), key = "OrderSignDelayMarked")
    })
    public void consumer(String message) {
        logger.info("接收订单签收延期原因事件：{}", message);
        var orderMessage = messageConverter.convert(message);
        logger.info("订单消息转化后：{}", orderMessage);
        //转发
        DomainEventPublisher.publish(new OrderChanged(orderMessage.getOrder(), "OrderSignDelayMarked"));
    }
}
